/**
 * \file LogFile.cpp
 *	\brief LogFile declaration class
 * \author Edouard ROGE
 * \date 12 septembre 2010
 */

// to disable warnings from windows compilation
#define  _CRT_SECURE_NO_WARNINGS

#include "LogManager.h"
#include "LogFile.h"

namespace Core
{
	namespace Log
	{
		LogFile::LogFile(const char * _filepath)
			: Logger(), m_strFile(_filepath)
		{
			m_pActiveObject = ActiveObject::CreateActiveObject();
			FILE * pFile = fopen(m_strFile.c_str(), "w");
			fclose(pFile);
		}

		LogFile::~LogFile()
		{
			m_pActiveObject.reset();

			LogManager::GetInstance().RemoveLogger(this);
		}

		void LogFile::Write(const std::string & _str)
		{
			m_pActiveObject->Send(std::bind(&LogFile::Log, this, _str));
		}

		void LogFile::Log(std::string _str)
		{
			auto pFile = fopen(m_strFile.c_str(), "a");
			fprintf(pFile, "%s", _str.c_str());
			fclose(pFile);
		}
	}
}